<%= form_for [:shop, @order], html: { class: "card" } do |f| %>
<div class="row row-cards row-deck">
  <div class="col-12">
    <div class="card-body">
      <h5>订单信息</h5>
      <div class="row">
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">订单编号</label>
            <div class="form-control-plaintext"><%= @order.trade_no %></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">下单时间</label>
            <div class="form-control-plaintext"><%= formattime(@order.created_at, unit: "hour") %></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">付款方式</label>
            <div class="form-control-plaintext"><%= i18n_enum @order, :pay_method %></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">状态</label>
            <div class="form-control-plaintext"><%= i18n_enum @order, :state %></div>
          </div>
        </div>
      </div>
      <div class="line"></div>
      <h5>用户信息</h5>
      <div class="row">
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">下单用户姓名</label>
            <div class="form-control-plaintext"><%= @order.user.nickname %></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">下单用户账号</label>
            <div class="form-control-plaintext"><%= @order.user.phone %></div>
          </div>
        </div>
      </div>
      <div class="line"></div>
      <h5>物流信息</h5>
      <div class="row">
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">收货姓名</label>
            <div class="form-control-plaintext"><%= @order.buyer_name %></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">收货手机</label>
            <div class="form-control-plaintext"><%= @order.buyer_phone %></div>
          </div>
        </div>
        <div class="col-md-12">
          <div class="form-group">
            <label class="form-label">快递方式</label>
            <div class="form-control-plaintext"><%= @order.address %></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">快递方式</label>
            <div class="form-control-plaintext"><%= @order.need_express ? "快递" : "自提" %></div>
          </div>
        </div>
        <% if (@order.checkouted? || @order.sent?) && @order.need_express %>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">快递公司（<%= link_to "查看费率", shop_logistics_companies_path %>）</label>
            <%= f.select :logistics_company_id, LogisticsCompany.all.select('id, name').map{ |c| [c.name, c.id] }, { include_blank: '请选择快递公司' }, { class: 'form-control select' } %>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">快递单号</label>
            <%= f.text_field :logistics_trade_no, class: "form-control" %>
          </div>
        </div>
        <%= f.hidden_field :state, value: "sent"%>
        <% end %>
      </div>
      <div class="line"></div>
      <h5>金额信息</h5>
      <div class="row">
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">结算金额<small>（已扣减运费和优惠）</small></label>
            <% if @order.pending? %>
            <%= f.number_field :total_fee, class: "form-control", step: '0.01', min: '0.01' %>
            <% else %>
            <div class="form-control-plaintext"><%= @order.total_fee %></div>
            <% end %>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">运费金额</label>
            <div class="form-control-plaintext"><%= @order.express_fee %></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <label class="form-label">优惠扣减金额</label>
            <div class="form-control-plaintext"><%= @order.coupon_fee %></div>
          </div>
        </div>
      </div>
      <div class="line"></div>
      <h5>商品信息</h5>
      <table class="table table-hover table-outline table-vcenter text-nowrap card-table">
        <thead>
          <tr>
            <th>商品</th>
            <th>规格</th>
            <th>单价</th>
            <th>数量</th>
            <th>金额</th>
            <th>优惠券说明</th>
          </tr>
        </thead>
        <tbody>
          <% @order.order_items.each do |order_item| %>
            <tr>
              <td><%= order_item.spu_name %></td>
              <td><%= order_item.option_value_presentation %></td>
              <td><%= order_item.fee %></td>
              <td><%= order_item.quantity %></td>
              <td><%= order_item.fee * order_item.quantity %></td>
              <td><%=  %></td>
            </tr>
          <% end %>
        </tbody>
      </table>
    </div>
    <div class="card-footer text-right">
      <div class="d-flex">
        <%= f.submit "保 存", class: "btn btn-primary ml-auto" %>
      </div>
    </div>
  </div>
</div>
<% end %>